package com.heyun.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.heyun.bean.CustomerConstitute;
import com.heyun.bean.Message;
import com.heyun.service.CustomerConstituteService;


@Controller
public class CustomerConstituteController {
	
	@Autowired
	private CustomerConstituteService customerConstituteService;
	
	@RequestMapping("/listCountByMonth")
	@ResponseBody
	public Message listCountByMonth(@RequestParam(value="pn",defaultValue="1")Integer pn){
		//引入pageHelper插件
		//在查询之前调用PageHelper.startPage(pn, 5)方法，传入要查询的页数(pn)和每页显示的数据数量(5)
		PageHelper.startPage(pn, 2);
		//startPage()后面紧跟的就是一个分页查询的数据
		List<CustomerConstitute> countCustomerByMonth = customerConstituteService.countCustomerByMonth();
		//使用PageInfo包装查询后的结果，只要将PageInfo交个页面就行了
		//封装了详细的分页信息，包括查询出来的数据，传入连续显示的页数
		PageInfo<CustomerConstitute> page = new PageInfo<CustomerConstitute>(countCustomerByMonth,2);
		
		return Message.success().add("pageInfo", page);
	}
	
}
